//
//  GRHoMeAnnotationView.m
//  YC_GRice
//
//  Created by Feng Liu on 2018/9/28.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRHoMeAnnotationView.h"

@interface GRHoMeAnnotationView ()

@property (nonatomic, strong) UIButton *paoBtn;

@end


@implementation GRHoMeAnnotationView

- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupLabel];
    }
    return self;
}

- (void)setupLabel {
    self.bounds = CGRectMake(0, 0, 35, 73);
    _pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.width/2-17.5, self.height/2-21.5, 35, 43)];
    _pinImageView.image = [UIImage imageNamed:@"Home_28"];
    [self addSubview:_pinImageView];

    _paoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _paoBtn.frame = CGRectMake(self.width/2 - KscreenWidth/15 * 2, self.pinImageView.y - 30, KscreenWidth/15 * 4, 30);
    _paoBtn.userInteractionEnabled = NO;
    _paoBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 8);
    _paoBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [_paoBtn setTitleColor:KGMBLACK_COLOR forState:UIControlStateNormal];
    _paoBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [_paoBtn setBackgroundImage:[UIImage imageNamed:@"Home_27"] forState:UIControlStateNormal];
    [self addSubview:_paoBtn];
}

-(void)didTappedAnnotationView {
    if ([self.delegate respondsToSelector:@selector(didAnnotationViewTapped:)]) {
        [self.delegate didAnnotationViewTapped:self];
    }
}

-(void)setShopName:(NSString *)shopName {
    CGFloat width = [shopName adaptiveWidth:30 font:13];
    if (width > (KscreenWidth/15 * 4)) {
        self.paoBtn.width = KscreenWidth/15 * 4;
        self.paoBtn.x       = self.width/2 - KscreenWidth/15 * 2;
    }else {
        self.paoBtn.width = width + 20;
        self.paoBtn.x       = self.width/2 - width/2 - 10;
    }
    [self.paoBtn setTitle:shopName forState:UIControlStateNormal];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
